using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VARTBQ
    {
        public DataRow Convert2ARTBQ(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryARTBQ(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ABQMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ABQKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["ABQWERK"] = " ".PadRight(3 ); 
         dwReturn["ABQABT"] = " ".PadRight(3 ); 
         dwReturn["ABQWAKZ"] = " ".PadRight(1 ); 
         dwReturn["ABQART"] = " ".PadRight(20 ); 
         dwReturn["ABQVAR"] = " ".PadRight(3 ); 
         dwReturn["ABQFARBE"] = " ".PadRight(10 ); 
         dwReturn["ABQDESS"] = " ".PadRight(10 ); 
         dwReturn["ABQCOL"] = " ".PadRight(10 ); 
         dwReturn["ABQBESCH"] = " ".PadRight(10 ); 
         dwReturn["ABQZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["ABQLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["ABQAENZL"] = " ".PadRight(0 ); 
         dwReturn["ABQAENB"] = " ".PadRight(8 ); 
         dwReturn["ABQAEND"] = " ".PadRight(0 ); 
         dwReturn["ABQNEUB"] = " ".PadRight(8 ); 
         dwReturn["ABQNEUD"] = " ".PadRight(0 ); 
         dwReturn["ABQSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["ABQPRIO"] = " ".PadRight(2 ); 
         dwReturn["ABQLART"] = " ".PadRight(20 ); 
         dwReturn["ABQLVAR"] = " ".PadRight(3 ); 
         dwReturn["ABQLARTBEZ"] = " ".PadRight(40 ); 
         dwReturn["ABQLFARBE"] = " ".PadRight(10 ); 
         dwReturn["ABQLDESS"] = " ".PadRight(10 ); 
         dwReturn["ABQLCOL"] = " ".PadRight(10 ); 
         dwReturn["ABQLBESCH"] = " ".PadRight(10 ); 
         dwReturn["ABQLFARBBEZ"] = " ".PadRight(20 ); 
         dwReturn["ABQPRGRP"] = " ".PadRight(1 ); 
         dwReturn["ABQURLAND"] = " ".PadRight(3 ); 
         dwReturn["ABQEAN"] = " ".PadRight(13 ); 
         dwReturn["ABQMINMG"] = " ".PadRight(0 ); 
         dwReturn["ABQMEEH"] = " ".PadRight(3 ); 
         dwReturn["ABQTOLV"] = " ".PadRight(0 ); 
         dwReturn["ABQTOLB"] = " ".PadRight(0 ); 
         dwReturn["ABQLIEFZT"] = " ".PadRight(0 ); 
         dwReturn["ABQPRUEFANW"] = " ".PadRight(1 ); 
         dwReturn["ABQFILLER"] = " ".PadRight(121 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapARTBQ(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveARTBQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryARTBQ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapARTBQ(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertARTBQ(dwLocal, ITXDBVERSION);
            }
            UpdateARTBQ(dwLocal);
        }
        public void InsertARTBQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ARTBQ(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryARTBQ(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ARTBQ WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ARTBQ  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ARTBQ";
            Return = Result;
            return Return;
        }
        public void DeleteARTBQ(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ARTBQ   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateARTBQ(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ARTBQ SET "
                    +"ABQMANDANT= :ABQMANDANT,"
                    +"ABQKUNDNR= :ABQKUNDNR,"
                    +"ABQWERK= :ABQWERK,"
                    +"ABQABT= :ABQABT,"
                    +"ABQWAKZ= :ABQWAKZ,"
                    +"ABQART= :ABQART,"
                    +"ABQVAR= :ABQVAR,"
                    +"ABQFARBE= :ABQFARBE,"
                    +"ABQDESS= :ABQDESS,"
                    +"ABQCOL= :ABQCOL,"
                    +"ABQBESCH= :ABQBESCH,"
                    +"ABQZUSTAND= :ABQZUSTAND,"
                    +"ABQLIEFNR= :ABQLIEFNR,"
                    +"ABQAENZL= :ABQAENZL,"
                    +"ABQAENB= :ABQAENB,"
                    +"ABQAEND= :ABQAEND,"
                    +"ABQNEUB= :ABQNEUB,"
                    +"ABQNEUD= :ABQNEUD,"
                    +"ABQSTAKZ= :ABQSTAKZ,"
                    +"ABQPRIO= :ABQPRIO,"
                    +"ABQLART= :ABQLART,"
                    +"ABQLVAR= :ABQLVAR,"
                    +"ABQLARTBEZ= :ABQLARTBEZ,"
                    +"ABQLFARBE= :ABQLFARBE,"
                    +"ABQLDESS= :ABQLDESS,"
                    +"ABQLCOL= :ABQLCOL,"
                    +"ABQLBESCH= :ABQLBESCH,"
                    +"ABQLFARBBEZ= :ABQLFARBBEZ,"
                    +"ABQPRGRP= :ABQPRGRP,"
                    +"ABQURLAND= :ABQURLAND,"
                    +"ABQEAN= :ABQEAN,"
                    +"ABQMINMG= :ABQMINMG,"
                    +"ABQMEEH= :ABQMEEH,"
                    +"ABQTOLV= :ABQTOLV,"
                    +"ABQTOLB= :ABQTOLB,"
                    +"ABQLIEFZT= :ABQLIEFZT,"
                    +"ABQPRUEFANW= :ABQPRUEFANW,"
                    +"ABQFILLER= :ABQFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ABQMANDANT", OracleType.NVarChar).Value = dwData["ABQMANDANT"].ToString(); 
          or1.Parameters.Add("ABQKUNDNR", OracleType.NVarChar).Value = dwData["ABQKUNDNR"].ToString(); 
          or1.Parameters.Add("ABQWERK", OracleType.NVarChar).Value = dwData["ABQWERK"].ToString(); 
          or1.Parameters.Add("ABQABT", OracleType.NVarChar).Value = dwData["ABQABT"].ToString(); 
          or1.Parameters.Add("ABQWAKZ", OracleType.NVarChar).Value = dwData["ABQWAKZ"].ToString(); 
          or1.Parameters.Add("ABQART", OracleType.NVarChar).Value = dwData["ABQART"].ToString(); 
          or1.Parameters.Add("ABQVAR", OracleType.NVarChar).Value = dwData["ABQVAR"].ToString(); 
          or1.Parameters.Add("ABQFARBE", OracleType.NVarChar).Value = dwData["ABQFARBE"].ToString(); 
          or1.Parameters.Add("ABQDESS", OracleType.NVarChar).Value = dwData["ABQDESS"].ToString(); 
          or1.Parameters.Add("ABQCOL", OracleType.NVarChar).Value = dwData["ABQCOL"].ToString(); 
          or1.Parameters.Add("ABQBESCH", OracleType.NVarChar).Value = dwData["ABQBESCH"].ToString(); 
          or1.Parameters.Add("ABQZUSTAND", OracleType.NVarChar).Value = dwData["ABQZUSTAND"].ToString(); 
          or1.Parameters.Add("ABQLIEFNR", OracleType.NVarChar).Value = dwData["ABQLIEFNR"].ToString(); 
          or1.Parameters.Add("ABQAENZL", OracleType.NVarChar).Value = dwData["ABQAENZL"].ToString(); 
          or1.Parameters.Add("ABQAENB", OracleType.NVarChar).Value = dwData["ABQAENB"].ToString(); 
          or1.Parameters.Add("ABQAEND", OracleType.NVarChar).Value = dwData["ABQAEND"].ToString(); 
          or1.Parameters.Add("ABQNEUB", OracleType.NVarChar).Value = dwData["ABQNEUB"].ToString(); 
          or1.Parameters.Add("ABQNEUD", OracleType.NVarChar).Value = dwData["ABQNEUD"].ToString(); 
          or1.Parameters.Add("ABQSTAKZ", OracleType.NVarChar).Value = dwData["ABQSTAKZ"].ToString(); 
          or1.Parameters.Add("ABQPRIO", OracleType.NVarChar).Value = dwData["ABQPRIO"].ToString(); 
          or1.Parameters.Add("ABQLART", OracleType.NVarChar).Value = dwData["ABQLART"].ToString(); 
          or1.Parameters.Add("ABQLVAR", OracleType.NVarChar).Value = dwData["ABQLVAR"].ToString(); 
          or1.Parameters.Add("ABQLARTBEZ", OracleType.NVarChar).Value = dwData["ABQLARTBEZ"].ToString(); 
          or1.Parameters.Add("ABQLFARBE", OracleType.NVarChar).Value = dwData["ABQLFARBE"].ToString(); 
          or1.Parameters.Add("ABQLDESS", OracleType.NVarChar).Value = dwData["ABQLDESS"].ToString(); 
          or1.Parameters.Add("ABQLCOL", OracleType.NVarChar).Value = dwData["ABQLCOL"].ToString(); 
          or1.Parameters.Add("ABQLBESCH", OracleType.NVarChar).Value = dwData["ABQLBESCH"].ToString(); 
          or1.Parameters.Add("ABQLFARBBEZ", OracleType.NVarChar).Value = dwData["ABQLFARBBEZ"].ToString(); 
          or1.Parameters.Add("ABQPRGRP", OracleType.NVarChar).Value = dwData["ABQPRGRP"].ToString(); 
          or1.Parameters.Add("ABQURLAND", OracleType.NVarChar).Value = dwData["ABQURLAND"].ToString(); 
          or1.Parameters.Add("ABQEAN", OracleType.NVarChar).Value = dwData["ABQEAN"].ToString(); 
          or1.Parameters.Add("ABQMINMG", OracleType.NVarChar).Value = dwData["ABQMINMG"].ToString(); 
          or1.Parameters.Add("ABQMEEH", OracleType.NVarChar).Value = dwData["ABQMEEH"].ToString(); 
          or1.Parameters.Add("ABQTOLV", OracleType.NVarChar).Value = dwData["ABQTOLV"].ToString(); 
          or1.Parameters.Add("ABQTOLB", OracleType.NVarChar).Value = dwData["ABQTOLB"].ToString(); 
          or1.Parameters.Add("ABQLIEFZT", OracleType.NVarChar).Value = dwData["ABQLIEFZT"].ToString(); 
          or1.Parameters.Add("ABQPRUEFANW", OracleType.NVarChar).Value = dwData["ABQPRUEFANW"].ToString(); 
          or1.Parameters.Add("ABQFILLER", OracleType.NVarChar).Value = dwData["ABQFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
